package com.china.produce.executor.impl;

import com.china.produce.executor.JobHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2023/7/2
 */
public class DemoMethodJobHandler extends JobHandler {

     private final Object target;

     private final Method method;

    public DemoMethodJobHandler(Object target, Method method) {

        this.target = target;

        this.method = method;
    }

    @Override
    public void execute()  {
        Class<?>[] parameterTypes = method.getParameterTypes();

        if (parameterTypes.length > 0) {
            try {
                method.invoke(target, new Object[parameterTypes.length]);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }else {
            try {
                method.invoke(target);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }
}
